import http from '@/plugins/axios'

export function getScriptManagePage(data) {
  return http({
    method: 'POST',
    url: '/ykf/customerSubAccount/onLinePage',
    data
  }).then(res => {
    const l = []
    res.list.forEach((item, cIndex) => {
      const subAccountList = item.subAccountList || []
      if (!subAccountList.length) {
        l.push({ ...item, rowspan: 1 })
        return
      }
      subAccountList.forEach((chlid, index) => {
        const rowspan = index ? 0 : subAccountList.length
        const colspan = index ? 0 : 1
        l.push({ ...item, ...chlid, rowspan, colspan, _index: cIndex + 1 })
      })
    });
    return { ...res, list: l }
  })
}

export function updateCustomerSubAccountStatus(data) {
  return http({
    method: 'POST',
    url: '/ykf/customerSubAccount/updateStatus',
    data
  })
}

export function removeScriptManagePage(data) {
  return http({
    method: 'POST',
    url: '/ykf/customerSubAccount/delete',
    data
  })
}
